from flask import Flask
from logging.config import dictConfig
from controllers.k8s_controller import k8s_bp
from services.k8s_service import test_k8s_connection
from utils.dingtalk import generate_ascii_art

app = Flask(__name__)

# 日志配置（保持不变）
dictConfig({
    'version': 1,
    'formatters': {'default': {
        'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
    }},
    'handlers': {'wsgi': {
        'class': 'logging.StreamHandler',
        'stream': 'ext://flask.logging.wsgi_errors_stream',
        'formatter': 'default'
    }},
    'root': {
        'level': 'DEBUG',
        'handlers': ['wsgi']
    }
})

# 注册蓝图
app.register_blueprint(k8s_bp)


@app.route("/")
def main():
    return "Please see the detailed documentation: https://gitee.com/yunwe/kubeupdate.git"


if __name__ == '__main__':
    with app.app_context():
        test_k8s_connection()
    from waitress import serve

    generate_ascii_art("Kubeupdate", font="block")
    serve(app, host='0.0.0.0', port=5000)
